/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;


import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

/**
 *
 * @author A0077454
 */
@Entity
public class Invoice implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long invoiceId;
    private String invoiceNum;
    @ManyToOne(cascade = {CascadeType.PERSIST})
    private Customer customer;
    @ManyToOne(cascade = {CascadeType.PERSIST})
    private SalesOrder saleOrder;
    @OneToOne(cascade = {CascadeType.PERSIST}, mappedBy="invoice")
    private DeliveryOrder deliveryOrder;
    @OneToMany(cascade = {CascadeType.PERSIST})
    private List<SalesItem> saleItems = new ArrayList();
    @OneToMany(cascade = {CascadeType.PERSIST})
    private List<Transaction> transactions = new ArrayList();
    @OneToOne(cascade = {CascadeType.PERSIST})
    private Address address;
    private String invoiceTo;  
    private String phone;
   
    private String specialTerm;
    
    private Integer gst;
    private String additionalChargeDesc;
    private Double additionalCharge;
    private String additionalChargeType;
    private String transportChargeType;
    private Double transportCharge;
    private Double amountPaid;
    private Double amountDue;
    private String status;
    @ManyToOne(cascade = {CascadeType.PERSIST})
    private SendReminder reminder;
    private Date createdDate;
    @OneToOne(cascade = {CascadeType.PERSIST})
    private SystemUser createdBy;
    public Invoice() {
    }
    
    public void create(String invoiceNum, String invoiceTo, String phone,  String specialTerm, Integer gst, String additionalChargeDesc, Double additionalCharge, String additionalChargeType, String transportChargeType, Double transportCharge, Double amountPaid, Double amountDue, String status, Date createdDate) {
        this.invoiceNum = invoiceNum;
        this.invoiceTo = invoiceTo;
        this.phone = phone;
        this.specialTerm = specialTerm;
        this.gst = gst;
        this.additionalChargeDesc = additionalChargeDesc;
        this.additionalCharge = additionalCharge;
        this.additionalChargeType = additionalChargeType;
        this.transportChargeType = transportChargeType;
        this.transportCharge = transportCharge;
        this.amountPaid = amountPaid;
        this.amountDue = amountDue;
        this.status = status;
        this.createdDate = createdDate;
    }
    
    
    

    public Double getAmountDue() {
        return amountDue;
    }

    public void setAmountDue(Double amountDue) {
        this.amountDue = amountDue;
    }

    public Double getAmountPaid() {
        return amountPaid;
    }

    public void setAmountPaid(Double amountPaid) {
        this.amountPaid = amountPaid;
    }

    
    public List<Transaction> getTransactions() {
        return transactions;
    }

    public void setTransactions(List<Transaction> transactions) {
        this.transactions = transactions;
    }
    
    
    

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    
    public Double getAdditionalCharge() {
        return additionalCharge;
    }

    public void setAdditionalCharge(Double additionalCharge) {
        this.additionalCharge = additionalCharge;
    }

    public String getAdditionalChargeDesc() {
        return additionalChargeDesc;
    }

    public void setAdditionalChargeDesc(String additionalChargeDesc) {
        this.additionalChargeDesc = additionalChargeDesc;
    }

    public String getAdditionalChargeType() {
        return additionalChargeType;
    }

    public void setAdditionalChargeType(String additionalChargeType) {
        this.additionalChargeType = additionalChargeType;
    }

    public Integer getGst() {
        return gst;
    }

    public void setGst(Integer gst) {
        this.gst = gst;
    }

    public List<SalesItem> getSaleItems() {
        return saleItems;
    }
    

    public void setSaleItems(List<SalesItem> saleItems) {
        this.saleItems = saleItems;
    }

    public Double getTransportCharge() {
        return transportCharge;
    }

    public void setTransportCharge(Double transportCharge) {
        this.transportCharge = transportCharge;
    }

    public String getTransportChargeType() {
        return transportChargeType;
    }

    public void setTransportChargeType(String transportChargeType) {
        this.transportChargeType = transportChargeType;
    }

    
    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

  
    public String getInvoiceNum() {
        return invoiceNum;
    }

    public void setInvoiceNum(String invoiceNum) {
        this.invoiceNum = invoiceNum;
    }

    
    
    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public DeliveryOrder getDeliveryOrder() {
        return deliveryOrder;
    }

    public void setDeliveryOrder(DeliveryOrder deliveryOrder) {
        this.deliveryOrder = deliveryOrder;
    }

    public SalesOrder getSaleOrder() {
        return saleOrder;
    }

    public void setSaleOrder(SalesOrder saleOrder) {
        this.saleOrder = saleOrder;
    }   
    
    public String getInvoiceTo() {
        return invoiceTo;
    }

    public void setInvoiceTo(String invoiceTo) {
        this.invoiceTo = invoiceTo;
    }

    public SystemUser getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(SystemUser createdBy) {
        this.createdBy = createdBy;
    }

    public Date getcreatedDate() {
        return createdDate;
    }

    public void setcreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

   
    public Long getInvoiceId() {
        return invoiceId;
    }

    public void setInvoiceId(Long invoiceId) {
        this.invoiceId = invoiceId;
    }

   

   
    public String getSpecialTerm() {
        return specialTerm;
    }

    public void setSpecialTerm(String specialTerm) {
        this.specialTerm = specialTerm;
    }
    

    

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (invoiceId != null ? invoiceId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Invoice)) {
            return false;
        }
        Invoice other = (Invoice) object;
        if ((this.invoiceId == null && other.invoiceId != null) || (this.invoiceId != null && !this.invoiceId.equals(other.invoiceId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Invoice[ id=" + invoiceId + " ]";
    }
    
    
    //// THINN CHANGES /////
    public void addTransaction(Transaction transaction)
    {
        this.transactions.add(transaction);
    }
    
    public void addSaleItems(SalesItem s)
    {
        this.saleItems.add(s);
    } 
    
    
    
    ///CHANGES - Replace payment period with payment term
    @ManyToOne
    private PaymentTerm paymentTerm;
         
     
     
    public PaymentTerm getPaymentTerm() {
        return paymentTerm;
    }

    public void setPaymentTerm(PaymentTerm paymentTerm) {
        this.paymentTerm = paymentTerm;
    }
}
